/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PostCollection.java
 *
 * Created on 21/04/2011, 8:54:06 PM
 */
package view.client;

import java.util.ArrayList;
import javax.swing.Box;
import util.EPanelTypes;

/**
 *
 * @author S3224743
 */
public class PostCollection extends javax.swing.JPanel
{
    //private fields
    private ArrayList<PostPanel>posts;
    private BaseClient baseClient;
    private int topicID;

    //private static field
    private static PostCollection postCollection;

    //public constructor
    private PostCollection(BaseClient baseClient)
    {
        this.initComponents();

        //Instantiate
        this.posts=new ArrayList<PostPanel>();
        this.baseClient=baseClient;
        this.topicID=0;

        //sample
//        this.sampleInit();
//        this.showPosts(EPanelTypes.ADMIN);
    }//end of public PostCollection(BaseClient baseClient)

    //Properties
    public BaseClient getBaseClient()
    {
        return this.baseClient;
    }

    public ArrayList<PostPanel> getPosts()
    {
        return this.posts;
    }

    public int getTopicID()
    {
        return this.topicID;
    }
    
    public void setTopicID(int topicID)
    {
        this.topicID=topicID;
    }

    //public static methods
    public static PostCollection getInstance(BaseClient baseClient)
    {
        if(postCollection==null)
            postCollection=new PostCollection(baseClient);
        return postCollection;
    }

    //private methods
//    private void sampleInit()
//    {
//        for(int iLoop=0;iLoop<10;iLoop++)
//        {
//            this.posts.add(new PostPanel());
//        }
//    }

    private void clearCollectionPanel()
    {
        this.collectionPanel.removeAll();
        this.collectionPanel.revalidate();
    }

    //public methods
    public void showPosts(EPanelTypes ePanelTypes)
    {
        this.clearCollectionPanel();
        for(PostPanel post:posts)
        {
            post.showAdminPanel(ePanelTypes);
            this.collectionPanel.add(post);
            this.collectionPanel.add(Box.createVerticalStrut(5));
        }
    }

    public void addPost(PostPanel post)
    {
        this.posts.add(post);
    }

    public void clearAllPosts()
    {
        this.posts.clear();
    }

    //
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        collectionPanel = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());

        collectionPanel.setLayout(new javax.swing.BoxLayout(collectionPanel, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane1.setViewportView(collectionPanel);

        add(jScrollPane1, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel collectionPanel;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
